package com.bensonbasement.snorflux.memory;

import java.util.List;

public class RBigEntity extends REntity implements IRSmallEntityHolder {

	private BigEntityInfo info;
	
	private IRBigEntityHolder location = null;
	private final RInventoryHelper inventoryHelper;
	
	public RBigEntity(RWorld world, BigEntityInfo info) {
		super(world);
		this.inventoryHelper = new RInventoryHelper();
		this.setInfo(info);
	}
	
	public void setInfo(BigEntityInfo info) {
		IRBigEntityHolder newLocation = (IRBigEntityHolder) this.getWorld().getWorldElement(info.getLocationID());
		if (newLocation != this.location) {
			this.setLocation(newLocation);
		}
		this.info = info;
	}
	
	@Override
	public void addSmallEntity(RSmallEntity entity) {
		this.inventoryHelper.addSmallEntity(entity);
	}

	@Override
	public void removeSmallEntity(RSmallEntity entity) {
		this.inventoryHelper.removeSmallEntity(entity);
	}

	@Override
	public List<RSmallEntity> getSmallEntities() {
		return this.inventoryHelper.getSmallEntities();
	}
	
	public void setLocation(IRBigEntityHolder newLocation) {
		IRBigEntityHolder oldLocation = this.location;
		if (newLocation != oldLocation) {
			if (oldLocation != null) {
				oldLocation.setBigEntity(null);
			}
			if (newLocation != null) {
				newLocation.setBigEntity(this);
			}
			this.location = newLocation;
		}

	}

	@Override
	public IRBigEntityHolder getLocation() {
		return location;
	}

	@Override
	public void leaveLocation() {
		this.setLocation(null);
	}

	@Override
	protected BigEntityInfo getInfo() {
		return this.info;
	}

}
